/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.N050;
import queenb.net.entitybean.N070;
import queenb.net.entitybean.N100;
import queenb.web.crm.store.CustomerStore;
import queenb.web.store.EmployeeStore;
import queenb.web.store.N050Store;
import queenb.web.store.N070Store;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Hung.Ngo
 */
public class N070Controller extends QueenbController {

    private int PN070;
    private String VN071;
    private N070Store store;
    private int FN100P;
    private int beginContrustor;
    private int FN100C;
    private int FN050;
    private int pn100;
    public N070Controller() {
        store = new N070Store();
        try {
            Object FNObject = getRequest().getParameter("id");
            if (FNObject != null) {
                FN100P = Util.parseInt(FNObject);
            }
        } catch (Exception e) {
        }

        Object action = getRequest().getParameter("action");
        if (action != null) {
            if (action.equals("addrelations")) {
                Object Pn100P = getRequest().getParameter("PN100P");
                Object PN100C = getRequest().getParameter("PN100C");
                if (Pn100P != null) {
                    FN100P = Util.parseInt(Pn100P);
                }
                if (PN100C != null) {
                    FN100C = Util.parseInt(PN100C);
                }
                System.out.println("-----------PP---" + FN100P + "-------FNC------" + FN100C);

                updateN070();
            } else if (action.equals("checkupdaterelations")) {

                Object PN050O = getRequest().getParameter("PN050");
                Object PN100C = getRequest().getParameter("PN100C");
                Object Pn100P = getRequest().getParameter("PN100P");
                if (PN050O != null) {
                    FN050 = Util.parseInt(PN050O);
                }
                if (PN100C != null) {
                    FN100C = Util.parseInt(PN100C);
                }
                if (Pn100P != null) {
                    FN100P = Util.parseInt(Pn100P);
                }
                System.out.println("-----------PP---" + FN100P + "-------FNC------" + FN100C+"------050------"+FN050);
                updateRow(FN050, FN100C, FN100P);
            };
        }

    }
    
    public void updateRow(int P050,int PC, int PP){
        try {
            CustomerStore store = new CustomerStore();
            int row = store.update2ColumnTAB(null, "N070", "FN050",String.valueOf(P050), "FN100P", PP, "FN100C", PC,getLogin().getUserName());
            System.out.println("-------------KAKKAKAA-------"+row);
              if (row > 0) {
                setBeginContrustor(1);
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                setBeginContrustor(0);
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        } catch (Exception e) {
        }
    }

    public void updateN070() {
        try {
            int row = store.updateN070(FN100P, FN100C, 0, VN071, getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            System.out.println("-----------PP---" + FN100P + "-------FNC------" + FN100C + "-----------------00000==" + row);
            if (row > 0) {
                setBeginContrustor(1);
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                setBeginContrustor(0);
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }

        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }

    public List<N050> getListitemrelations() {
        try {
            N050Store store = new N050Store();
            List<N050> listN10000 = store.findAllN050ForCombo(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
//           N100 n100 = new N100();
//           listN10000.add(0,n100.getNamecombox());
            System.out.println("--------------------------" + listN10000.size());
            return listN10000;
        } catch (Exception e) {
            return null;
        }
    }

    public List<N070> getListALlN050() {
        try {
                 if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                FN100P = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
            List<N070> list = store.getListN050(getLogin().getModule(), getLogin().getCompanyNo(), FN100P, getLogin().getUserName());
            return list;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @return the PN070
     */
    public int getPN070() {
        return PN070;
    }

    /**
     * @param PN070 the PN070 to set
     */
    public void setPN070(int PN070) {
        this.PN070 = PN070;
    }

    /**
     * @return the VN071
     */
    public String getVN071() {
        return VN071;
    }

    /**
     * @param VN071 the VN071 to set
     */
    public void setVN071(String VN071) {
        this.VN071 = VN071;
    }

    /**
     * @return the FN100P
     */
    public int getFN100P() {
         if(SessionProvider.getSessionMapValue("PN100HD")!=null){
            FN100P = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
        return FN100P;
    }

    /**
     * @param FN100P the FN100P to set
     */
    public void setFN100P(int FN100P) {
        this.FN100P = FN100P;
    }

    /**
     * @return the beginContrustor
     */
    public int getBeginContrustor() {
        return beginContrustor;
    }

    /**
     * @param beginContrustor the beginContrustor to set
     */
    public void setBeginContrustor(int beginContrustor) {
        this.beginContrustor = beginContrustor;
    }

    /**
     * @return the FN100C
     */
    public int getFN100C() {
        return FN100C;
    }

    /**
     * @param FN100C the FN100C to set
     */
    public void setFN100C(int FN100C) {
        this.FN100C = FN100C;
    }

    /**
     * @return the FN050
     */
    public int getFN050() {
        return FN050;
    }

    /**
     * @param FN050 the FN050 to set
     */
    public void setFN050(int FN050) {
        this.FN050 = FN050;
    }

    /**
     * @return the pn100
     */
    public int getPn100() {
           if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                pn100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
        return pn100;
    }

    /**
     * @param pn100 the pn100 to set
     */
    public void setPn100(int pn100) {
        this.pn100 = pn100;
    }
}
